//添加 删除
// const { Model } = require("mongoose");
const {tagModel} = require("../mongodb");
//const toast = require("../toast");
const { success,fail } = require("../toast");



module.exports = function (router){
       //查询
router.get("/tag",async(ctx)=>{
       toast(tagModel.find(({})));
    
    try {
        const data =await tagModel.find({});
           return  success(ctx,data);
    } catch (error) {
           return fail(ctx,error);
    }
})
//添加
router.post("/tag",async(ctx)=>{
    try {
        const data = await  tagModel.create(ctx.request.body);
           return  success(ctx,data);
    } catch (error) {
           return fail(ctx,error);
    }
   
    
 })
//删除
 router.delete("/tag",async ctx=>{
    try {
        const data = await tagModel.deleteOne(ctx.request.body);
           return  success(ctx,data);
    } catch (error) {
           return fail(ctx,error);
    }
 })
 


}
/*
{
    status:200,
    data:{},
    msg:""
}

*/